import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ShowIntroduceServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
        String s=request.getParameter("intro");
        Cookie[] cookies=request.getCookies();
        Cookie cookie1=null;
        Cookie cookie2=null;
        Cookie cookie3=null;
//        Cookie cookie4=null;

//        out.println("intro-"+s+"-title");

        for (Cookie cookie:cookies){
            if(cookie.getName().equals("introduce-"+s+"-kind")){
                cookie1=new Cookie("intro-now-kind",cookie.getValue());

            } else if(cookie.getName().equals("introduce-"+s+"-title")) {
                cookie2 = new Cookie("intro-now-title", cookie.getValue());
            }else if(cookie.getName().equals("introduce-"+s+"-content")){
                cookie3=new Cookie("intro-now-content",cookie.getValue());
            }else if(cookie.getName().equals("introduce-"+s+"-img")){
//                cookie4=new Cookie("intro-now-img",cookie.getValue());
            }
        }
        out.println(cookie1.getValue());
        out.println(cookie2.getValue());
        out.println(cookie3.getValue());
//        out.println(cookie4.getValue());
        out.println(43435);
        cookie1.setMaxAge(60*60*60);
        cookie2.setMaxAge(60*60*60);
        cookie3.setMaxAge(60*60*60);
//        cookie4.setMaxAge(60*60*60);
        out.println(43435);
        cookie1.setPath(request.getContextPath()+"/");
        cookie2.setPath(request.getContextPath()+"/");
        cookie3.setPath(request.getContextPath()+"/");
//        cookie4.setPath(request.getContextPath()+"/");
        out.println(43435);
        response.addCookie(cookie1);
        response.addCookie(cookie2);
        response.addCookie(cookie3);
//        response.addCookie(cookie4);

        out.println(43435);
        response.sendRedirect("show-introduce.jsp");
    }
}
